package com.hellobike.haxing.modules.order.send;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 取消订单发送backendMq
 */
@Component
@Data
@Slf4j
public class OrderCancelBackendSend {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 有结单时间时发送backend
     *
     * @param orderId
     */
    public void sendOrderCancel(Long orderId) {
        rocketMQTemplate.asyncSend("cancel-order-topic", orderId, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                log.info("==cancel-order-topic=success==orderId=>{}", orderId);
            }

            @Override
            public void onException(Throwable e) {
                log.error("==cancel-order-topic==send error==>", e);
            }
        });
    }
}
